package com.zy.web.controller.business;

import com.zy.business.domain.TbShift;
import com.zy.business.service.ShiftService;
import com.zy.common.annotation.Log;
import com.zy.common.core.controller.BaseController;
import com.zy.common.core.domain.AjaxResult;
import com.zy.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * @description: 班次管理
 * @author: whf
 * @create: 2023-02-07 09:18
 **/
@RestController
@Api(tags = "班次管理接口")
@RequestMapping("/shift")
public class ShiftController extends BaseController {

    @Autowired
    private ShiftService tbShiftService;

    @ApiOperation("获取班次信息")
    @PreAuthorize("@ss.hasPermi('business:shift:query')")
    @GetMapping
    public AjaxResult getInfo()
    {
        return AjaxResult.success(tbShiftService.selectTbShiftById());
    }

    @ApiOperation("新增班次")
    @PreAuthorize("@ss.hasPermi('business:shift:edit')")
    @Log(title = "班次管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbShift shift)
    {
        shift.setCreateBy(getUsername());
        return toAjax(tbShiftService.insertTbShift(shift));
    }

    @ApiOperation("修改班次")
    @PreAuthorize("@ss.hasPermi('business:shift:edit')")
    @Log(title = "班次管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbShift shift)
    {
        shift.setUpdateBy(getUsername());
        return toAjax(tbShiftService.updateTbShift(shift));
    }

}
